// Map of characters to width per em, generated from Adobe Clean Spectrum VF.
// Multiply by the font size to get the pixel width.
let letters: Record<string, number> = {
  '0': 0.5467998461797813,
  '1': 0.33863281002940315,
  '2': 0.4949392889121938,
  '3': 0.5016111737184715,
  '4': 0.5308981693435971,
  '5': 0.5023057133155973,
  '6': 0.5481826272455199,
  '7': 0.46165110064312254,
  '8': 0.5277358292705409,
  '9': 0.5432406635520582,
  A: 0.6059440599655305,
  B: 0.5832495796806406,
  C: 0.5565531328751679,
  D: 0.6598042449318364,
  E: 0.5300641635661462,
  F: 0.5081749911055526,
  G: 0.6455998072113557,
  H: 0.6693259321022943,
  I: 0.2697145809246694,
  J: 0.32189760597286665,
  K: 0.5840943795209466,
  L: 0.501062476701323,
  M: 0.8308132582427056,
  N: 0.6825471255294288,
  O: 0.6920027568250859,
  P: 0.5665339951757473,
  Q: 0.6920027568250859,
  R: 0.5871806978309012,
  S: 0.4962879123859901,
  T: 0.5402653527717012,
  U: 0.6519305325732583,
  V: 0.6040336065898666,
  W: 0.8548425854690754,
  X: 0.5435315369653245,
  Y: 0.537968827408557,
  Z: 0.5471876252326289,
  a: 0.4964378641768902,
  b: 0.5449183176910446,
  c: 0.43080009202470115,
  d: 0.5425954554028817,
  e: 0.5017767421059094,
  f: 0.2770022918782831,
  g: 0.5140052743477447,
  h: 0.5515482646395446,
  i: 0.24808137309258887,
  j: 0.24821074492252418,
  k: 0.4986819080010872,
  l: 0.26457503647320485,
  m: 0.8461911554090422,
  n: 0.5513497527462953,
  o: 0.5444509990673368,
  p: 0.5447198057977952,
  q: 0.5452413834173114,
  r: 0.34813664273642425,
  s: 0.4001812142580505,
  t: 0.3153228837303483,
  u: 0.5453896125268208,
  v: 0.48007624993851516,
  w: 0.7385096424408182,
  x: 0.456618258856363,
  y: 0.47805235885526454,
  z: 0.4210896632430806,
  ' ': 0.22853845854089036,
  '!': 0.29312679093582983,
  '@': 0.8559711917318172,
  '#': 0.523247739616419,
  '$': 0.5030891266153872,
  '%': 0.8450454594859704,
  '^': 0.5117092967393077,
  '&': 0.6946158587165351,
  '*': 0.4013355993759323,
  '(': 0.35453398280709264,
  ')': 0.3521490453929629,
  _: 0.5150663688638459,
  '-': 0.32678529376509985,
  '+': 0.5590725652733067,
  '=': 0.5494543793394757,
  '.': 0.20820494555165425,
  ',': 0.2075588140991205,
  '/': 0.3632512652560671
};

// Gets the width of a string of text. Multiply by font size to get pixel width.
export function getTextWidth(s: string) {
  let width = 0;
  for (let c of s) {
    let w = letters[c];
    if (w != null) {
      width += w;
    }
  }

  return width;
}
